<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div,
        p {
            width: 300px;
            height: 30px;
            line-height: 30px;
            color: #fff;
            background-color: pink;
        }
    </style>
</head>

<body>
    <button>显示当前系统时间</button>
    <div></div>
    <p></p>
    <script>
        //获取元素
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        var p = document.querySelector('p');
        //注册事件
        btn.onclick = function() {
            div.innerHTML = getDate();
        }
       

        function getDate() {
             var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var dates = date.getDate();
            var day = date.getDay();
            var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ];

            return '今天是' + year + '年' + month + '月' + dates + '日' + arr[day];
        }
        p.innerHTML = getDate();
       
    </script>
</body>

</html>